#ifndef __clib_rbtree_h__
#define __clib_rbtree_h__

#include <inttype.h>

typedef struct _rbt_node
{
	struct _rbt_node *pl, *pr, *pp;
	void *key;
	void *val;
	int flag;
} rbt_node, *rbt_iterator;

typedef struct _rbtree
{
	rbt_node *root;
	compare cmp;
	int32 size;
} rbtree;

rbtree* rbt_create( compare _cmp );
void rbt_destroy( rbtree *_rbt );
rbt_iterator rbt_insert( rbtree *_rbt, void *_key, void *_val );
void* rbt_remove( rbtree *_rbt, void *_key );
rbt_iterator rbt_find( rbtree *_rbt, void *_key );
rbt_iterator rbt_begin( rbtree *_rbt );
rbt_iterator rbt_end( rbtree *_rbt );
rbt_iterator rbt_next( rbt_iterator _it );
rbt_iterator rbt_pre( rbt_iterator _it );

#endif // __clib_rbtree_h__
